package com.nova.edc.service.system.impl;

import com.nova.edc.dao.system.MapAreaDao;
import com.nova.edc.model.system.MapArea;
import com.nova.edc.service.system.MapAreaService;
import com.nova.frame.dao.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @param
 * @author <a href="mailto:huzhanjun@novacloud.com">huzj</a>
 * @version : 1.0
 * @date 2016-01-11 10:02
 */
public class MapAreaServiceImpl implements MapAreaService {
    @Autowired
    private MapAreaDao mapAreaDao;

    @Override
    public List<MapArea> findMapAreaByExample(MapArea mapArea) {
        return mapAreaDao.findByExample(mapArea);
    }

    @Override
    public List<MapArea> findCityAreaByProvince(String province) {
        MapArea mapArea = getAreaByName(province.trim());
        if (mapArea != null) {
            return mapAreaDao.query().add(Restrictions.eq("t_map_area.ParentId", mapArea.getId())).list();
        }
        return null;
    }

    @Override
    public MapArea getAreaByName(String name) {
        return mapAreaDao.query().add(Restrictions.eq("t_map_area.Name", name.trim())).get();
    }

    @Override
    public int update(MapArea mapArea) {
        return mapAreaDao.updateNotNull(mapArea);
    }
}
